package sweezy.swf.tools.flex
{
	import flash.utils.ByteArray;

	public class PropertyItem
	{

		public var name:String;

		public var type:Class;

		public var value:Object;

		public function PropertyItem(name:String, type:Class, value:Object)
		{
			this.name = name;
			this.type = type;
			this.value = value;
		}

		public function get data():*
		{
			return value === null ? null : value[name];
		}

		public function get text():String
		{
			var obj:Object = data;
			if (obj is ByteArray)
			{
				return "[ByteArray]";
			}
			else if (obj !== null)
			{
				return String(obj);
			}

			return "";
		}

		public function set text(value:String):void
		{
			if (this.value === null)
			{
				return;
			}

			if (type === int)
			{
				this.value[name] = int(value);
			}
			else if (type === uint)
			{
				this.value[name] = uint(value);

			}
			else if (type === Boolean)
			{
				this.value[name] = value === "true";
			}
			else if (type === Number)
			{
				this.value[name] = Number(value);
			}
			else if (type === String)
			{
				this.value[name] = value;
			}
		}

		public function get typeName():String
		{
			if (type === int)
			{
				return "int";
			}
			if (type === uint)
			{
				return "uint";
			}
			if (type === Boolean)
			{
				return "Boolean";
			}
			if (type === Number)
			{
				return "Number";
			}
			if (type === String)
			{
				return "String";
			}
			if (type === ByteArray)
			{
				return "ByteArray";
			}

			return "";
		}
	}
}
